package com.ebs.md.api.abs;

/**
 * Perforce Revision:
 *  $File: //depot/MarketData/commons-md-api/MAIN/src/test/java/com/ebs/md/api/abs/ImplAbsAggrOrderBook.java $
 *  $Revision: #3 $  $Change: 114409 $  $DateTime: 2012/09/02 09:29:07 $  $Author: Arik.Sher $
 */

import java.util.NavigableSet;
import java.util.SortedMap;

import com.ebs.md.api.IAggregatedByPriceBookEntry;
import com.ebs.md.api.IIdentifiedOrder;
import com.ebs.md.api.IProduct;
import com.ebs.md.api.Rate;


public class ImplAbsAggrOrderBook
extends AbstractAggrOrderBook
{
	protected Tracer tracer;
	
	public ImplAbsAggrOrderBook(Tracer tracer) {
		super(new PR(), null, null);
		this.tracer = tracer;
	}
	
	
	void beforeNewBookEntry(IAggregatedByPriceBookEntry newBookEntry, IIdentifiedOrder order) {
		tracer.lastTrigger = "beforeNewBookEntry";
		tracer.affectedBookEntry = newBookEntry;
		tracer.orderWhichAffects = order;
		
		SortedMap<Rate, NavigableSet<IAggregatedByPriceBookEntry>> theBook = getAffectedOBSide(order.getSide());

		if ( !theBook.isEmpty() ) {
			tracer.topRateBeforeChange      = theBook.firstKey();
			tracer.topBookEntryBeforeChange = focusOnFirstOnly(theBook, tracer.topRateBeforeChange);
			tracer.bottomRateBeforeChange      = theBook.lastKey();
			tracer.bottomBookEntryBeforeChange = focusOnFirstOnly(theBook, tracer.bottomRateBeforeChange);
		}
	}

	void beforeRemovingBookEntry(IAggregatedByPriceBookEntry bookEntry,	IIdentifiedOrder order) {
		tracer.lastTrigger = "beforeRemovingBookEntry";
		tracer.affectedBookEntry = bookEntry;
		tracer.orderWhichAffects = order;

		SortedMap<Rate, NavigableSet<IAggregatedByPriceBookEntry>> theBook = getAffectedOBSide(order.getSide());

		if ( !theBook.isEmpty() ) {
			tracer.topRateBeforeChange      = theBook.firstKey();
			tracer.topBookEntryBeforeChange = focusOnFirstOnly(theBook, tracer.topRateBeforeChange);
			tracer.bottomRateBeforeChange      = theBook.lastKey();
			tracer.bottomBookEntryBeforeChange = focusOnFirstOnly(theBook, tracer.bottomRateBeforeChange);
		}
	}
	
	static class PR implements IProduct
	{
		// gened via Eclipse
		private static final long serialVersionUID = -4142864210000922558L;

		public String getName() {
			return "DummyProduct";
		}
		
	}
}
